/*
 * @Author: wangqizhang
 * @Date: 2024-05-02 16:28:57
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-12 14:56:28
 * @FilePath: /suixinji-server/service/group.service.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
const { runSqlTask, initSqlTask } = require('./index');
const { Group } = require('../model/group.model');

class GroupService {
  async findAll(ctx) {
    try {
      const userId = ctx.state.user.id;
      const res = await runSqlTask(
        initSqlTask(Group, 'findAll', { user_id: userId })
      );
      return res;
    } catch (error) {
      return error;
    }
  }
  async addData(ctx) {
    try {
      const res = await runSqlTask(initSqlTask(Group, 'create', ctx));
      return res;
    } catch (error) {
      return error;
    }
  }
  async updateData(ctx) {
    try {
      const res = await runSqlTask(
        initSqlTask(Group, 'update', ctx.request.body)
      );
      return res;
    } catch (error) {
      return error;
    }
  }
  async findDataByQuery(ctx) {
    console.log(ctx.request.body, 222);
    try {
      const res = await runSqlTask(initSqlTask(Group, 'pageQuery', ctx));
      return res;
    } catch (error) {
      return error;
    }
  }
}
module.exports = new GroupService();
